$(function() {
    var params = {
        "month":"",
        "festival":"",
        "allSuit":"",
        "season":"",
        "tripMode":"",
        "travelTimeType":""
    }
    $(".month").click(function () {
        var $month = $(this);
        $('.month').removeClass("on");
        $('#destSearch').empty();
        params.month = $month.data("month");
        if (params.month == '') {
            params.festival = '';
            $('.month, .festival').removeClass("on");
            $month.addClass("on");
            $.get("/destinationSearch/searchDestDetail", params, function (data) {
                soStupid(data);
            })
        }else {
            $month.addClass("on");
            $.get("/destinationSearch/searchDestDetail", params, function (data) {
                soStupid(data);
            })
        }

    })
    $(".festival").click(function () {
        var $festival = $(this);
        $('.festival').removeClass("on");
        $festival.addClass("on");
        $('#destSearch').empty();
        params.festival = $festival.data("festival");
        console.log(params);
        $.get("/destinationSearch/searchDestDetail", params, function (data) {
            soStupid(data);
        })
    })
    $(".allSuit").click(function () {
        var $allSuit = $(this);
        console.log($allSuit);
        $('.allSuit').removeClass("on");
        $('#destSearch').empty();
        params.allSuit = $allSuit.data("allsuit");
        if (params.allSuit == ''){
            params.season = '';
            params.tripMode = '';
            $('.allSuit,.season,.tripMode').removeClass("on");
            $allSuit.addClass("on");
            $.get("/destinationSearch/searchDestDetail", params, function (data) {
                soStupid(data);
            })
        }else {
            $allSuit.addClass("on");
            $.get("/destinationSearch/searchDestDetail", params, function (data) {
                soStupid(data);
            })
        }

    })
    $(".season").click(function () {
        var $season = $(this);
        $('.season').removeClass("on");
        $season.addClass("on");
        $('#destSearch').empty();
        params.season = $season.data("season");
        console.log(params);
        $.get("/destinationSearch/searchDestDetail", params, function (data) {
            soStupid(data);
        })
    })
    $(".tripMode").click(function () {
        var $tripMode = $(this);
        $('.tripMode').removeClass("on");
        $tripMode.addClass("on");
        $('#destSearch').empty();
        params.tripMode = $tripMode.data("tripmode");
        console.log(params);
        $.get("/destinationSearch/searchDestDetail", params, function (data) {
            soStupid(data);
        })
    })
    $(".travelTimeType").click(function () {
        var $travelTimeType = $(this);
        console.log($travelTimeType);
        $('.travelTimeType').removeClass("on");
        $travelTimeType.addClass("on");
        $('#destSearch').empty();
        params.travelTimeType = $travelTimeType.data("traveltime");
        $.get("/destinationSearch/searchDestDetail", params, function (data) {
            soStupid(data);
        })
    })
        var url = location.search; //获取url中"?"符后的字串
        var value;
        var paramName;
        if (url.indexOf("?") != -1) {    //判断是否有参数
            var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
            strs = str.split("=");   //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
            value = decodeURIComponent(strs[1]);          //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
            var keys = Object.keys(params);
            for (var i in keys) {
                if (keys[i] == strs[0]) {
                    params[keys[i]] = value;
                }
            }
        }

    $('.festival,.allSuit,.season,.tripMode').each(function () {
            var $class = $(this);
            var confirm = $class.text();
            if (value == confirm) {
                $class.addClass("on");
            }
        })
    function soStupid(data) {
        var dataObj = eval(data);
        var list = dataObj.list;
        for (var i in list) {
            var places = list[i].places;
            var temp;
            for (var j in places){
                $('#temp').append('<a href="javascript:;" target="_blank">'+places[j]+'</a>\n' +
                    '                <span class="divide"></span>')
            }
            $('#destSearch').append('<li class="item">\n' +
                '        <div class="img">\n' +
                '            <a href="" data-id='+list[i].id+' target="_blank"><img height="200" width="320" src='+list[i].coverUrl+' style="display: inline;">\n' +
                '                <div class="title">'+list[i].name+'</div>\n' +
                '            </a>\n' +
                '        </div>\n' +
                '        <div class="info">\n' +
                '            <p class="detail">'+list[i].summary+'</p>\n' +
                '            <div class="hot">\n' +
                '                <span class="label" id="temp">TOP3</span>\n' +$('#temp').html()+
                '            </div>\n' +
                '            <div class="line"><a href="javascript:;" target="_blank"><em>1</em>'+list[i].duration+'</a></div>\n' +
                '        </div>\n' +
                '    </li>'
            )
        }
        $('#destSearch').append(
            '<div style="float: right">\n' +
            '    <div style="float: left;" ><span style="line-height:30px"> 共页 '+dataObj.pageNum+'/ '+dataObj.pageSize+'条&nbsp;&nbsp;&nbsp;</span></div>\n' +
            '    <div id="pagination" class="jq-pagination" style="display: inline;"></div>\n' +
            '</div>'
        )
        $("#pagination").jqPaginator({
            totalPages: dataObj.pages||1,
            visiblePages: 5,
            currentPage: dataObj.pageNum||1,
            prev: '<a class="prev" href="javascript:void(0);">上一页<\/a>',
            next: '<a class="next" href="javascript:void(0);">下一页<\/a>',
            page: '<a href="javascript:void(0);">'+dataObj.pageNum+'<\/a>',
            last: '<a class="last" href="javascript:void(0);" >尾页<\/a>',
            onPageChange: function(page, type) {
            if(type == 'change'){
                $("#currentPage").val(page);
                $("#searchForm").submit();
            }
                // var dataObj = eval(data);
                // var list = dataObj.list;
                // for (var i in list) {
                //     i.log
                //     var places = i.places;
                //     var temp;
                //     for (var j in places){
                //         temp.append('<a href="javascript:;" target="_blank">'+places[j]+'</a>\n' +
                //             '                <span class="divide"></span>')
                //     }
                //     $('#destSearch').append('<li class="item">\n' +
                //         '        <div class="img">\n' +
                //         '            <a href="" data-id='+list[i].id+' target="_blank"><img height="200" width="320" src='+list[i].coverUrl+' style="display: inline;">\n' +
                //         '                <div class="title">'+list[i].name+'</div>\n' +
                //         '            </a>\n' +
                //         '        </div>\n' +
                //         '        <div class="info">\n' +
                //         '            <p class="detail">'+list[i].summary+'</p>\n' +
                //         '            <div class="hot">\n' +
                //         '                <span class="label">TOP3</span>\n' +temp+
                //         '            </div>\n' +
                //         '            <div class="line"><a href="javascript:;" target="_blank"><em>1</em>'+list[i].duration+'</a></div>\n' +
                //         '        </div>\n' +
                //         '    </li>')
                // }
        }
    })
    }
});